<!doctype html>
<html>
<!--
Copyright 2015 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<head>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <link href="//fonts.googleapis.com/css?family=Roboto|Roboto+Mono" rel="stylesheet">
  <script src="treevis.js"></script>
  <link href="treevis.css" rel="stylesheet">
</head>
<body>

<div class="treevis example-cards">
  <div class="treevis-root framelayout">

    <div class="cardlist scrollable nolayer linearlayout vertical">
      <div class="card card-1" data-elevation="2">
        <span class="card-image" style="background-color: #00BCD4"></span>
        <span class="card-title">Bacon</span>
        <span class="card-desc">Bacon ipsum dolor amet pork belly meatball kevin spare ribs. Frankfurter swine corned beef meatloaf, strip steak.</span>
      </div>
      <div class="card card-2" style="position: relative;" data-elevation="2">
        <span class="card-image" style="background-color: #FFC107"></span>
        <span class="card-title">Ribs</span>
        <span class="card-desc">Bacon ipsum dolor amet pork belly meatball kevin spare ribs. Frankfurter swine corned beef meatloaf, strip steak.</span>
      </div>
      <div class="card card-3" style="position: relative;" data-elevation="2">
        <span class="card-image" style="background-color: #00BCD4"></span>
        <span class="card-title">Ribs</span>
        <span class="card-desc">Bacon ipsum dolor amet pork belly meatball kevin spare ribs. Frankfurter swine corned beef meatloaf, strip steak.</span>
      </div>
    </div>

    <div class="appbar" data-elevation="4">
      <svg style="left: 16px;" width="24" height="24" viewBox="0 0 24 24"><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"/></svg>
      <span class="title">Screen Title</span>
      <svg style="right: 16px;" width="8" height="24" viewBox="8 0 8 24"><path d="M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"/></svg>
    </div>

    <div class="fab" data-elevation="4">
      <svg width="24" height="24" viewBox="0 0 24 24"><path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/></svg>
    </div>

  </div>
</div>

<div class="xmltree">
CoordinatorLayout                                                                     %.treevis-root
  AppBarLayout                                                                        %.appbar
    Toolbar app:layout_scrollFlags=scroll|enterAlways layout_height=?actionBarSize    %.appbar
  RecyclerView app:layout_behavior=@string/appbar_scrolling_view_behavior             %.cardlist
    CardView                                                                          %.card-1
    CardView                                                                          %.card-2
    ...
  FloatingActionButton layout_gravity=bottom|right                                    %.fab
</div>

<script>

var lastScrollTop = 0;
$('.cardlist').on('scroll', function() {
  var scrollTop = $(this).scrollTop();
  var deltaTop = scrollTop - lastScrollTop;
  var appbarTop = $('.appbar').position().top;
  console.log(appbarTop);
  $('.appbar').css({top:Math.min(0,Math.max(appbarTop - deltaTop, -$('.appbar').height() - 8))});
  lastScrollTop = scrollTop;
});

</script>

<style>

/* general */

html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

body {
  display: flex;
  flex-direction: row;
}

.treevis {
  flex: 1 0 0;
  background: #f7f7f7;
  font-family: Roboto;
}

.xmltree {
  background: #fff;
  flex: 1 0 0;
}

.treevis-root {
  background-color: #e5e5e5;
  width: 360px;
  height: 640px;
}

.fab {
  right: 16px;
  bottom: 16px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
}

.fab svg {
  position: absolute;
  width: 24px;
  height: 24px;
  left: 50%;
  top: 50%;
  margin-left: -12px;
  margin-top: -12px;
}

.cardlist {
  height: 100%;
  box-sizing: border-box;
  padding-top: 56px;
  padding-bottom: 88px;
  overflow: scroll;
}

.card {
  background: #fff;
  border-radius: 2px;
  overflow: hidden;
}

/* cards example */

.example-cards .appbar {
  background-color: #3f51b5;
  width: 100%;
  height: 56px
}

.example-cards .card {
  margin: 8px;
}

.example-cards .card + .card {
  margin-top: 0;
}

.example-cards .card-image,
.example-cards .card-title,
.example-cards .card-desc {
  display: block;
}

.example-cards .card-image {
  height: 164px;
  background-size: cover;
}

.example-cards .card-title {
  margin: 16px;
  font-size: 20px;
  font-weight: 500;
  color: #000;
}

.example-cards .card-desc {
  margin: -8px 16px 16px 16px;
  font-size: 14px;
  color: #888;
  line-height: 18px;
}

.example-cards .appbar {
  fill: white;
  color: #fff;
}

.example-cards .appbar svg {
  position: absolute;
  height: 24px;
  top: 16px;
}

.example-cards .appbar .title {
  position: absolute;
  left: 72px;
  line-height: 56px;
  font-size: 20px;
  font-weight: 500;
}

.example-cards .fab {
  background-color: #ff4081;
  fill: white;
}

</style>

</body>
</html>
